package tpc2;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.ArrayList;
import tpc2.CollectVotesLogic;

import commsCPN.JavaCPN;

public class CollectVotesRefactored {

    private static JavaCPN jCPN = null;
    private static Integer numOfWorkers = null;

    /**
     * Can be used for testing the CollectVotes module alone with the CPN-Model.
     * 
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {
        jCPN = new JavaCPN();
        CollectVotesLogic cVL = new CollectVotesLogic(jCPN);
        while (true) {
            System.out.println("Status: listening");
            jCPN.accept(9000);
            ArrayList<Integer> waitingAcknowledgements = cVL.run();
            StringBuilder sb = new StringBuilder();
            sb.append("AwaitingAcks:");
            for (Integer i : waitingAcknowledgements) {
                sb.append(i.toString() + ",");
            }
            jCPN.send(new ByteArrayInputStream(sb.toString().getBytes()));
            jCPN.send(new ByteArrayInputStream("Reset:".getBytes()));
            jCPN.disconnect();
            System.out.println("Status: completed");
        }
    }
}
